package leetcode.code0849;

import leetcode.helper.MaxDebug;

public class Solution extends Solution849 {

	@Override
	public int maxDistToClosest(int[] seats) {
		int max = 0;
		int left = -1;
		int len = seats.length;
		int maxLeft = 0;
		int maxRight = len - 1;
		int ansSiteLeft = 0;
		int i = 0;
		for (; i < len; i++) {
			if (seats[i] == 1) {
				ansSiteLeft = i;
				maxLeft = left;
				maxRight = i;
				max = i - left;
				left = i;
				break;
			}
		}
		//[0,1,1,1,0,0,1,0,0]
		for (; i < len; i++) {
			if (seats[i] == 1) {
				int distance = i - left;
				if (distance > max) {// 最大间距
					maxLeft = left;
					maxRight = i;
					max = distance;
				}
				left = i;
			}
		}
		int ans = (maxRight - maxLeft) >> 1;// 坐在中间，两边有人,最大距离
		int ansSiteRight = len - 1 - left; // 坐在最右边，left是坐在最右边的最后一个人
		return Math.max(Math.max(ansSiteLeft, ansSiteRight), ans);// 坐在中间，两边有人
	}

	public static void main(String[] args) {
		Solution so = new Solution();
		so.debug8();
		so.debug7();
		so.debug6();
		so.debug5();
		MaxDebug.debug14(so);

	}

}
